package cn.eonshine.cuba.inf.modular.biz.service.impl;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.eonshine.cuba.inf.common.http.InfStatus;
import cn.eonshine.cuba.inf.modular.basic.entity.Mapping;
import cn.eonshine.cuba.inf.modular.biz.entity.TankerGpsDatasheet;
import cn.eonshine.cuba.inf.modular.biz.mapper.TankerGpsDatasheetMapper;
import cn.eonshine.cuba.inf.modular.biz.service.ITankerGpsDatasheetService;
import cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService;

/**
 * <p>
 * Tanker GPS数据表 服务实现类
 * </p>
 *
 * @author Alan
 * @since 2018-07-28
 */
@Service
@Transactional
public class TankerGpsDatasheetServiceImpl extends AbstractCommonService<TankerGpsDatasheetMapper, TankerGpsDatasheet> implements ITankerGpsDatasheetService {

	@Override
	public int transportDataHandle(TankerGpsDatasheet obj, int count) throws Exception {
		BigDecimal vesselId = obj.getVesselId();
		Date dataInputDatetime = obj.getDataInputDatetime();
		QueryWrapper<TankerGpsDatasheet> entity = new QueryWrapper<TankerGpsDatasheet>();
//		entity.where("vessel_id={0} and data_input_datetime={1}", vesselId, dataInputDatetime);
		entity.lambda().eq(TankerGpsDatasheet::getVesselId, vesselId);
		entity.lambda().eq(TankerGpsDatasheet::getDataInputDatetime, dataInputDatetime);
		if(this.isUpdate==0){
			boolean isDelete = remove(entity);
			if (isDelete) {
				count++;
			}
		}else {
			boolean isupdate = update( obj,entity);
			if (isupdate) {
				count++;
			}
		}
		return count;
	}

	@Override
	public void mappingHandle(TankerGpsDatasheet obj) throws Exception {
		// mapping TABLE
		Mapping map = new Mapping();
		QueryWrapper<Mapping> entitys = new QueryWrapper<Mapping>();
		map.setLsmsId(obj.getId());
		map.setDmz1(obj.getVesselId().toString());
		map.setDataType(InfStatus.DMZ_MAPPING_SEA_TANKER_GPS);
		entitys.eq("lsms_id", obj.getId());
		Mapping maps = mappingService.getOne(entitys);
		if (maps == null) {
			mappingService.save(map);
		}else {
			mappingService.update(map, entitys);
		}
	}

	@Override
	public boolean isUseCutomerSelectSQL() {
		return false;
	}

}
